var form;
var $;
var table;
var productType;
var layer;
layui.use(['form','jquery','table','layer'],function() {
    form = layui.form;
    $ = layui.jquery;
    table = layui.table;
    layer = layui.layer;
    //获取选择的商品类型
    form.on('select(filter)', function(data){
        productType = data.value
    });
    //上架下架状态
    form.on('switch(swi)', function(data){
        var state;
        if(data.elem.checked){
            state = 1;
        }else{
            state = 2;
        }
    });
});
/*startTab();
function startTab() {
    $.ajax({
        url:'/Product/queryProduct',
        dataType:'json',
        success:function (data) {
            var arr = [];
            for (var i = 0; i<data.data.length;i++){
                if(data.data[i].result != 2){
                    arr.push(data.data[i]);
                }
            }
            tab(arr);
            console.log(arr);
        }
    });
}*/
$.ajax({
    url:'/Product/getNavIgation',
    dataType:'json',
    //data:{"parentId":$('#proId',window.parent.document).val()},
    success:function (data) {
        console.log(data);
        tab(data.data);
    }
});
function tab(data){
    table.render({
        elem: '#demo' ,
        data:data,
        toolbar:'#toolutil',
        page:true,
        cols:[[
            {checkbox:true},
            {field:'dictSort',title:'商品编号',align:'center'},
            {field:'dictLabel',title:'商品名称',align:'center'},
            {field:'dictValue',title:'原价',align:'center'},
            {field:'listClass',title:'现价',align:'center'},
            {field:'createTime',title:'操作时间',align:'center'},
        ]]
    });
}

//刷新
function refresh() {
    window.location.reload();
}

//搜索
function selProduct() {
    var dictSort = $('input[name = dictSort]').val();
    var dictLabel = $("input[name = dictLabel]").val();
    var createTime = $('input[name = createTime]').val();
    var product = {
        dictSort :dictSort,
        dictLabel:dictLabel,
        createTime:createTime
    }
    $.ajax({
        url:'/Product/getNavIgation',
        dataType:'json',
        data:product,
        success:function (data) {
            tab(data.data);
        }
    });
}
//重置
function reset(){
    $('input[name = title]').val("");
    $("select[name=proTitle]").val('0');
}

function dis() {
    $('#dis').hide();
}

function backOff() {
    var arr = localStorage.getItem("numArr");
    var numArr = arr.split(",");
    numArr.pop();
    window.parent.layui.element.tabChange('tab',numArr[numArr.length - 1]);
    localStorage.setItem("numArr",numArr);
}
